#ifndef OBR_ASNODE_H
#define OBR_ASNODE_H

#include "common.h"
#include "Matrix4x4f.h"
#include "CudaBuffer.h"
#include "helpers/Helpers.h"

namespace OBR
{
enum class ASNodeType
{
    IAS,
    GAS
};

class ASNode
{
private:
public:
    OptixTraversableHandle handle;
    ASNodeType type;    // IAS / GAS
    bool built = false; // indicate whether handle is ready to use
    size_t ref_cnt = 0; // times used by direct upper instance
    OptixAabb aabb;
    CudaBuffer d_aabb;

public:
    ASNode(ASNodeType _type = ASNodeType::IAS) : type(_type)
    {
    }

    ~ASNode()
    {
    }

    /**
     * @brief recursively build AccelStructure
     *
     * @param ctx
     * @param stream
     */
    virtual void buildAccelStructure(OptixDeviceContext &ctx, CUstream &stream)
    {
        built = true;
    }

    /**
     * @brief update current AS using states saved in object
     *
     */
    virtual void updateAccelStructure()
    {
    }

    /**
     * @brief set local to world transform to given parent value and pass down to children
     *
     * @param parent_l2w
     */
    virtual void updateLocalToWorld(Matrix4x4f l2w)
    {
    }
};

} // namespace OBR

#endif // ASNODE_H
